import Vue from 'vue'

import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import locale from 'element-ui/lib/locale/lang/en' // lang i18n

import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'

import '@/icons' // icon
import '@/permission' // permission control


import echarts from 'echarts'
Vue.prototype.$echarts = echarts //将echarts存到Vue原型中

/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
if (process.env.NODE_ENV === 'production') {
  const { mockXHR } = require('../mock')
  mockXHR()
}

// set ElementUI lang to EN
// Vue.use(ElementUI, { locale })
// 如果想要中文版 element-ui，按如下方式声明
Vue.use(ElementUI)
Vue.config.productionTip = false

//将DOM转为PDF
import htmlToPdf from "./utils/htmlToPdf.js"
Vue.use(htmlToPdf);

//配置JS生成PDF的公共函数
// import {createApp} from 'vue'
// import html2Canvas from 'html2canvas'
// import JsPDF from 'jspdf'
// const app = createApp(App);
// app.config.globalProperties.getPdf = function() {
//     var title = this.htmlTitle //PDF标题
//     html2Canvas(document.querySelector('#pdfDom'), {
//         allowTaint: true,
//         taintTest: false,
//         useCORS: true,
//         //width:960,
//         //height:5072,
//         dpi: window.devicePixelRatio * 4, //将分辨率提高到特定的DPI 提高四倍
//         scale: 4 //按比例增加分辨率
//     }).then(function(canvas) {
//         let contentWidth = canvas.width
//         let contentHeight = canvas.height
//         let pageHeight = contentWidth / 592.28 * 841.89
//         let leftHeight = contentHeight
//         let position = 0
//         let imgWidth = 595.28
//         let imgHeight = 592.28 / contentWidth * contentHeight
//         let pageData = canvas.toDataURL('image/jpeg', 1.0)
//         let PDF = new JsPDF('', 'pt', 'a4')
//         if (leftHeight < pageHeight) {
//             PDF.addImage(pageData, 'JPEG', 0, 0, imgWidth, imgHeight)
//         } else {
//             while (leftHeight > 0) {
//                 PDF.addImage(pageData, 'JPEG', 0, position, imgWidth, imgHeight)
//                 leftHeight -= pageHeight
//                 position -= 841.89
//                 if (leftHeight > 0) {
//                     PDF.addPage()
//                 }
//             }
//         }
//         PDF.save(title + '.pdf')
//     })
// }


new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
